"""
公共模块：常量
"""

from enum import Enum


class UserInfoConstants:
    """
    用户信息常量类
    """

    class Status(Enum):
        """
        状态枚举类
        """
        NORMAL = (1, "正常")
        FREEZE = (2, "冻结")
        DISABLE = (3, "停用")
        DELETE = (4, "删除")

        @classmethod
        def get_value_name(cls, key):
            for name, member in cls.__members__.items():
                value = member.value
                if len(value) == 2 and value[0] == key:
                    return value[1]
            return ""

    class Gender(Enum):
        """
        性别枚举类
        """
        MALE = (1, "男")
        FEMALE = (2, "女")

        @classmethod
        def get_value_name(cls, key):
            for name, member in cls.__members__.items():
                value = member.value
                if len(value) == 2 and value[0] == key:
                    return value[1]
            return ""


class SysConfigConstants:
    """
    系统配置信息常量类
    """

    class Type(Enum):
        """
        类型枚举类
        """
        SYS = (1, "系统底层配置")
        EMAIL_SMS = (2, "邮件/短信配置")

        @classmethod
        def get_value_name(cls, key):
            for name, member in cls.__members__.items():
                value = member.value
                if len(value) == 2 and value[0] == key:
                    return value[1]
            return ""


class StockInfoConstants:
    """
    股票信息常量类
    """

    class Type(Enum):
        """
        类型枚举类
        """
        SSE_A = (10, "上证A股主板")
        SZSE_A = (20, "深证A股主板")
        SZSE_C = (21, "深圳A股创业板")

        @classmethod
        def get_value_name(cls, key):
            for name, member in cls.__members__.items():
                value = member.value
                if len(value) == 2 and value[0] == key:
                    return value[1]
            return ""

        @classmethod
        def get_type(cls, stock_code):
            if not stock_code:
                return None

            if len(stock_code) != 6:
                # 只支持中国A股
                return None

            first_num = int(stock_code[0])
            if first_num == 6:
                return cls.SSE_A
            elif first_num == 0:
                return cls.SZSE_A
            elif first_num == 3:
                return cls.SZSE_C

            return None

    class Status(Enum):
        """
        状态枚举类
        """
        NORMAL = (10, "已上市")
        WARN = (20, "退市风险警告")
        DELIST_ING = (30, "退市中")
        DELIST = (31, "已退市")
        DELETE = (40, "删除")

        @classmethod
        def get_value_name(cls, key):
            for name, member in cls.__members__.items():
                value = member.value
                if len(value) == 2 and value[0] == key:
                    return value[1]
            return ""


class Whether(Enum):
    """
    是否的枚举类
    """

    NO = (0, "否")
    YES = (1, "是")

    @classmethod
    def get_value_name(cls, key):
        for name, member in cls.__members__.items():
            value = member.value
            if len(value) == 2 and value[0] == key:
                return value[1]
        return ""


class Switch(Enum):
    """
    开关的枚举类
    """

    NO = (0, "禁用")
    YES = (1, "启用")

    @classmethod
    def get_value_name(cls, key):
        for name, member in cls.__members__.items():
            value = member.value
            if len(value) == 2 and value[0] == key:
                return value[1]
        return ""


class ProvinceCity(Enum):
    """
    中国省市枚举类
    """

    # 4个直辖市
    BJ = (11, '北京')
    SH = (31, '上海')
    TJ = (12, '天津')
    CQ = (50, '重庆')

    # 5个自治区
    NM = (15, '内蒙古')
    GX = (45, '广西')
    XZ = (54, '西藏')
    NX = (64, '宁夏')
    XJ = (65, '新疆')

    # 23个省份
    HE = (13, '河北')
    SX = (14, '山西')
    LN = (21, '辽宁')
    JL = (22, '吉林')
    HL = (23, '黑龙江')
    JS = (32, '江苏')
    ZJ = (33, '浙江')
    AH = (34, '安徽')
    FJ = (35, '福建')
    JX = (36, '江西')
    SD = (37, '山东')
    HA = (41, '河南')
    HB = (42, '湖北')
    HN = (43, '湖南')
    GD = (44, '广东')
    HI = (46, '海南')
    SC = (51, '四川')
    GZ = (52, '贵州')
    YN = (53, '云南')
    SN = (61, '陕西')
    GS = (62, '甘肃')
    QH = (63, '青海')
    TW = (71, '台湾')

    # 2个特别行政区
    HK = (81, '香港')
    MO = (82, '澳门')

    @classmethod
    def get_value_name(cls, key):
        for name, member in cls.__members__.items():
            value = member.value
            if len(value) == 2 and value[0] == key:
                return value[1]
        return ""
